namespace Core.Infrastructure
{
	using System;
	using Domain;

	public abstract class DomainSession : IDisposable
	{
		public IAccountRepository AccountRepository
		{
			get
			{
				return this.EnsureRepostory<IAccountRepository>();
			}
		}

		public IPersonRepository PersonRepository
		{
			get
			{
				return this.EnsureRepostory<IPersonRepository>();
			}
		}

		public IAlertRepository AlertRepository
		{
			get
			{
				return this.EnsureRepostory<IAlertRepository>();
			}
		}		

		protected abstract TRepository EnsureRepostory<TRepository>();

		/// <summary>
		///		Push Unit-of-work to the database.
		/// </summary>
		public abstract void Flash();
	
		#region IDisposable Members

		void  IDisposable.Dispose()
		{
			this.Flash();
		}

		#endregion
	}
}